#include<conio.h>
#include<stdio.h>
#include<string.h>

struct hocsinh
{
       char hoten[20];
       int  namsinh;
       float toan,ly,hoa,tong;
      
      };
void nhap(hocsinh a[], int &n)
{
    printf("nhap so hoc sinh:");
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
        printf(" nhap hoc sinh thu %d",i+1);
        fflush(stdin);
        printf("\n nhap ho ten");
        gets(a[i].hoten);       
        printf("\n nhap nam sinh");
        scanf("%d",&a[i].namsinh);
        printf("\n nhap diem toan ly hoa:");
        scanf("%f %f %f",&a[i].toan,&a[i].ly,&a[i].hoa) ;
        printf("\n tong diem 3 mon :");
        printf("%.1f",a[i].tong=a[i].toan+a[i].hoa+a[i].ly);
}   
}
void xuat(hocsinh a[],int n)
{ int i;
printf("\n STT TEN NAM TOAN LY HOA TONG:\n");
       for (i=0;i<n;i++)
        printf("%2d %5s %d %.1f %.1f %.1f %.1f \n ",i+1,a[i].hoten,a[i].namsinh,a[i].toan,a[i].ly,a[i].hoa,a[i].tong);          
     }      
void sapxep(hocsinh a[],int n)
{    int i,j;
     hocsinh tg;
     printf ("      ");
      for( i=0;i<n-1;i++)
      for( j=1;j<n;j++)
      if(a[i].tong<a[j].tong)
      {
          tg=a[i];
          a[i]=a[j];
          a[j]=tg;  
       }
       printf("SAU KHI SAP XEP GIAM DAN TONG DIEM: \n");
       printf("\n STT TEN NAM TOAN LY HOA TONG:\n");
      for (i=0;i<n;i++)
        printf("%2d %5s %d %.1f %.1f %.1f %.1f \n ",i+1,a[i].hoten,a[i].namsinh,a[i].toan,a[i].ly,a[i].hoa,a[i].tong);          
        }
        
void tk(hocsinh a[],int n)
{
     char ht[20]; int ok=0;
     fflush(stdin);
     printf(" \n nhap ten can tim: ");
     gets(ht);
     for (int i=0;i<n;i++)
     if(stricmp(ht,a[i].hoten)==0)
     {
     ok=1;
     printf("%2d %5s %d %.1f %.1f %.1f %.1f \n ",i+1,a[i].hoten,a[i].namsinh,a[i].toan,a[i].ly,a[i].hoa,a[i].tong); 
     }
     if(ok==0) printf(" NO DI CHOI ROI");
       }
     
int main()
{hocsinh s[50];
int n;
nhap(s,n);
xuat(s,n);
sapxep(s,n);
tk(s,n);    
 getch();   
}
